package com.ucw.ucwclient.biz.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ucw.ucwclient.dal.dataobject.Account;
import com.ucw.ucwclient.dal.mapper.AccountFollowMapper;
import com.ucw.ucwclient.dal.mapper.AccountMapper;
import com.ucw.ucwclient.dal.search.NormalSearch;

@Service
public class UserService {

	@Resource
	private AccountMapper accountMapper;

	@Resource
	private AccountFollowMapper accountFollowMapper;

	public Map<String, String> followSomeone(Long followId, Long userId) {
		int result = accountFollowMapper.followOne(followId, userId, new Date());
		Map<String, String> resp = new HashMap<String, String>();
		if (result == 1) {
			resp.put("resultMsg", "success");
			resp.put("code", "200");
		} else {
			resp.put("resultMsg", "已经关注过此用户");
		}
		return resp;
	}

	public Map<String, String> cancelFollowSomeone(Long followId, Long userId) {
		int result = accountFollowMapper.deleteByPrimaryKey(followId, userId);
		Map<String, String> resp = new HashMap<String, String>();
		if (result == 1) {
			resp.put("resultMsg", "success");
			resp.put("code", "200");
		} else {
			resp.put("resultMsg", "你没有关注过该用户");
		}
		return resp;
	}

	public List<Account> checkOnesFollows(NormalSearch search) {
		List<Account> list = accountMapper.selectOnesFollowsByPageSearch(search);
		return list;
	}

	public List<Account> checkOnesFans(NormalSearch search) {
		List<Account> list = accountMapper.selectOnesFansByPageSearch(search);
		return list;
	}

}
